// 引入mockjs
import Mock from 'mockjs'
// import { options } from '../views/home/options'
const Random = Mock.Random

const menuList = [
  {
    title: '首页',
    url: '/home',
    icon: 'HomeFilled'
  }
  // {
  //   title: '页面管理',
  //   url: '/page',
  //   icon: 'Checked',
  //   children: [
  //     {
  //       title: '表单页',
  //       url: '/form',
  //       icon: 'Checked',
  //       children: [
  //         {
  //           title: '基础表单',
  //           url: '/baseForm',
  //           icon: 'Menu'
  //         },
  //         {
  //           url: '/stepFrom',
  //           title: '步骤表单',
  //           icon: 'Menu'
  //         },
  //         {
  //           url: '/advancedForm',
  //           title: '高级表单',
  //           icon: 'Menu'
  //         }
  //       ]
  //     },
  //     {
  //       title: '表格管理',
  //       icon: 'Grid',
  //       children: [
  //         {
  //           url: '/Department',
  //           title: '机构管理',
  //           icon: 'Menu'
  //         }
  //       ]
  //     },
  //     {
  //       url: '/ErrorMessage',
  //       title: '异常页面',
  //       icon: 'WarningFilled',
  //       children: [
  //         {
  //           url: '/404',
  //           title: '404',
  //           icon: 'Menu'
  //         },
  //         {
  //           url: '/500',
  //           title: '500',
  //           icon: 'Menu'
  //         }
  //       ]
  //     }
  //   ]
  // }
]

export const LoginInfo = (options) => {
  console.log(options, '接收post参数')
  const { username, password } = JSON.parse(options.body)
  // eslint-disable-next-line eqeqeq
  if (username == 'admin' && password != '123456') {
    return {
      code: '-200',
      data: {
        message: '用户不存在'
      }
    }
  } else {
    return {
      code: '200',
      data: {
        user_id: Random.id(),
        name: Random.cname(),
        token: Random.guid(),
        image:
          'https://img2.baidu.com/it/u=2859542338,3761174075&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1660064400&t=6fe6057370cbe369654ff2e132d02a37'
      }
    }
  }
}

export const getMenuList = (options) => {
  // const obj = JSON.parse(options.body)
  return {
    code: 200,
    data: {
      menuList: menuList
    }
  }
}

// 用户列表
let userList = []
for (let index = 0; index < 50; index++) {
  const obj = {
    id: Random.id(),
    username: Random.cname(),
    email: Random.email(),
    date: Random.date(),
    address: Random.city(true),
    content: Random.csentence()
  }
  userList.push(obj)
}
const param2Obj = (url) => {
  const obj = JSON.parse(url)
  const page = obj.page
  console.log(page)
  return page
}

export const UserList = (options) => {
  const currentPage = param2Obj(options.body)
  const cameraData = userList.filter((item, index) => {
    return index >= (currentPage - 1) * 10 && index < currentPage * 10
  })
  return {
    code: 200,
    data: {
      total: userList.length,
      userList: cameraData
    }
  }
}

export const addUserList = (options) => {
  console.log('传过来的数据' + JSON.parse(options.body))
  const obj = JSON.parse(options.body)
  obj.id = Random.id()
  userList.unshift(obj) // 将前台返回来的数据，拼接到数组中。
  return {
    data: userList,
    id: obj.id
  }
}

// 数据的修改操作
export const listUpdate = (options) => {
  const obj = JSON.parse(options.body)
  userList = userList.map((val) => {
    // eslint-disable-next-line eqeqeq
    return val.id == obj.id ? obj : val
  })
  return {
    data: userList
  }
}

export const Newslist = (options) => {
  // const obj = JSON.parse(options.body)
  const newList = []
  for (let i = 0; i < 10; i++) {
    const item = {
      title: Random.csentence(5, 8), //  Random.csentence( min, max )
      notifyPic: Random.dataImage('300x250', 'mock的图片'), // Random.dataImage( size, text ) 生成一段随机的 Base64 图片编码
      notifyType: Random.integer(1, 3), // 随机生成1-3的Integer
      isTop: Random.integer(1, 2), // 随机生成1-2的Integer
      createUser: Random.cname(), // Random.cname() 随机生成一个常见的中文姓名
      email: Random.email(),
      number: '$' + Random.integer(100, 5000) + '.00',
      createTime: Random.date() + ' ' + Random.time(),
      pay_state: '100' + Random.integer(1, 3)
    }
    newList.push(item)
  }
  return {
    data: newList
  }
}
export const orderLists = (options) => {
  const obj = JSON.parse(options.body)
  const orderList = []
  for (let i = 0; i < 60; i++) {
    const item = {
      goodsId: i,
      code: Random.guid(),
      title: Random.ctitle(4, 5),
      commodity: '10010' + i,
      goodsname: Random.cword(2, 6), //  Random.csentence( min, max )
      brand: Random.cword(2, 4),
      sku: '1ml', // Random.dataImage( size, text ) 生成一段随机的 Base64 图片编码
      inventory: Random.integer(10, 100),
      number: Random.integer(100, 5000), // 100到5000的随机整数
      costPrice: Random.integer(10, 20),
      amount: Random.integer(100, 200), // 100到5000的随机整数
      itemEdit: false,
      ItemData: [
        {
          address: Random.city(true),
          email: Random.email(),
          state: Random.boolean(),
          salenumber: Random.integer(10, 100),
          receivable: Random.integer(10, 100)
        }
      ]
    }
    orderList.push(item)
  }

  return {
    total: 60,
    // eslint-disable-next-line eqeqeq
    data: obj.size == 10 ? orderList.slice(obj.size * obj.page - obj.size, obj.size * obj.page) : orderList
  }
}

export const homeList = (options) => {
  const homeList = []
  for (let index = 0; index < 10; index++) {
    const obj = {
      name: '限时秒杀',
      title_id: Random.integer(0, 10) + 'id',
      type: Random.boolean(),
      number: Random.integer(10, 100),
      order_number: Random.integer(100, 1000),
      GWV_number: Random.integer(100, 5000),
      state: Random.boolean()
    }
    homeList.push(obj)
  }

  return {
    data: homeList
  }
}

export const noticeLists = (options) => {
  const noticeLists = []
  for (let index = 0; index < 10; index++) {
    const item = {
      text: Random.csentence()
    }
    noticeLists.push(item)
  }
  return {
    data: noticeLists
  }
}

export const cardlists = (options) => {
  // const obj = JSON.parse(options.body)
  const cardlists = []
  for (let i = 0; i < 50; i++) {
    const item = {
      title: Random.csentence(5, 8), //  Random.csentence( min, max )
      user_name: Random.cname(), // Random.cname() 随机生成一个常见的中文姓名
      email: Random.email(),
      number: '$' + Random.integer(100, 5000) + '.00',
      date: Random.date(),
      pay_state: '100' + Random.integer(1, 3),
      content: Random.csentence()
    }
    cardlists.push(item)
  }
  return {
    data: cardlists
  }
}
